package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.SupplyInventoryView;

public class SupplyInventoryViewPresenter extends AbstractPresenter<SupplyInventoryView> {
	final String SINGLEITEM = "supplyInventoryView";
	final String MULTIITEM = "supplyInventoryViews";
	
	public ArrayList<SupplyInventoryView> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public SupplyInventoryView tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public SupplyInventoryView createItemFromJSONObject(JSONObject jsonObject){
		SupplyInventoryView item = new SupplyInventoryView();
		try{
			item.setSupID(jsonObject.getInt("supID"));
			item.setSupName(jsonObject.getString("supName"));
			item.setSupOnHand(jsonObject.getDouble("supOnHand"));
			item.setSupOnOrder(jsonObject.getDouble("supOnOrder"));
			item.setSupSpoken(jsonObject.getDouble("supSpoken"));
			item.setSupUnits(jsonObject.getString("supUnits"));
			item.setSupWH(jsonObject.getInt("supWH"));
			item.setVersion(jsonObject.getInt("version"));
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(SupplyInventoryView item){
		try{
			JSONObject json = new JSONObject();
			json.put("supID", item.getSupID());
			json.put("supName", item.getSupName());
			json.put("supOnHand", item.getSupOnHand());
			json.put("supOnOrder", item.getSupOnOrder());
			json.put("supSpoken", item.getSupSpoken());
			json.put("supUnits", item.getSupUnits());
			json.put("supWH", item.getSupWH());
			json.put("version", item.getVersion());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public SupplyInventoryView getEmptyEntity(){
		SupplyInventoryView entity = new SupplyInventoryView();
		return entity;
	}
}
